#include "global.hpp"
#include "foreach.hpp"
#include "variable.hpp"

#include "storyscreen/interface.hpp"
#include "storyscreen/controller.hpp"

#include "display.hpp"
#include "game_events.hpp"
#include "gettext.hpp"
#include "intro.hpp"
#include "language.hpp"
#include "log.hpp"
#include "sound.hpp"
#include "text.hpp"

static lg::log_domain log_engine("engine");
#define LOG_NG LOG_STREAM(info, log_engine)

#include "stub.hpp"

namespace
{
	int count_segments(const config::const_child_itors& story)
	{
		config::const_child_iterator itor = story.first;
		int count = 0;
		while (itor != story.second)
		{
			++itor;
			++count;
		}
		return count;
	}
}

void show_story(display& disp, const std::string& scenario_name,
	const config::const_child_itors& story)
{
	const int total_segments = count_segments(story);
	int segment_count = 0;
	config::const_child_iterator itor = story.first;
	while (itor != story.second)
	{
		storyscreen::controller ctl(disp, vconfig(*itor, true),
			scenario_name, segment_count, total_segments);
		stroyscreen::STORY_RESULT result = ctl.show(startpos);

		switch (result)
		{
		case storyscreen::NEXT:
			if (itor != story.second)
			{
				++itor;
				++segment_count;
				startpos = storyscreen::START_BEGINNING;
			}
			break;
		case storyscreen::BACK:
			if (itor != story.first)
			{
				--itor;
				--segment_count;
				startpos = storyscreen::START_END;
			}
			break;
		case storyscreen::QUIT:
			return;
		}
	}
	return;
}

void show_endscreen(display&, const t_string&, unsigned int)
{
	STUB();
	LOG_NG << "show_endscreen() invoked...\n";

	config story_cfg;

	LOG_NG << "show_endscreen() completed...\n";
}
